const isNull = (obj: any): boolean => {
  if (typeof obj === 'undefined') {
    return true;
  } else if (typeof obj === 'object') {
    if (obj == null || !Object.keys(obj).length) {
      return true;
    }
  } else if (typeof obj === 'string' && obj == '') {
    return true;
  } else if (typeof obj === 'number' && obj == 0) {
    return true;
  }
  return false;
};
const isNullAndNotZero = (obj: any): boolean => {
  return isNull(obj) && obj !== 0;
};
const copy = <T>(obj: T): T => {
  return JSON.parse(JSON.stringify(obj));
};
const stringify = (obj: any): string => {
  if (isNull(obj)) return '';
  return JSON.stringify(obj);
};
const parse = <T>(obj: string): T | undefined => {
  if (isNull(obj)) return undefined;
  return JSON.parse(JSON.stringify(obj));
};
const parseTime = (date: string): string => {
  return date.substr(date.indexOf('T') + 1, 8);
};
const parseDate = (date: string): string => {
  return date.substr(0, date.indexOf('T'));
};
const parseDateTime = (date: string): string => {
  const s = date.replace('T', ' ');
  return s.substr(0, 19);
};
export { isNull, copy, stringify, parse, isNullAndNotZero, parseDate, parseDateTime, parseTime };
